﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Might.Infrastructure.Services;

namespace Might.UIControls.StatusBar {
    public partial class StatusBarViewItem {
        private IProgressToken progressToken;
        private IStatusBarView sb;

        public StatusBarViewItem(IStatusBarView sb) {
            this.sb = sb;
            InitializeComponent();
        }

        public void Activate(IProgressToken token) {
            progressToken = token;
            progressToken.ProgressGo += progressToken_ProgressGo;
            progressToken_ProgressGo(progressToken, progressToken.State);
        }

        private void progressToken_ProgressGo(IProgressToken sender, ProgressEventArgs e) {
            UserStateTxt.Text = e.UserState;
            Progress.Value = e.Percentage;

            if (e is EndProgressEventArgs) {
                ResultTxt.Text = (e as EndProgressEventArgs).Result.ToString();
                progressToken.ProgressGo -= progressToken_ProgressGo;
                sb.RemoveItem(this);
            }
        }
    }
}
